<?php
namespace app\repair\validate;
use app\validate\Common;
use think\Validate;
use think\Db;
class Repair extends Common
{
	/*验证规则*/
	protected $rule = [
		'repair_sn'			=> 'require|repair_sn',
		'state'				=> 'require|in:0,1,2,3,4,5,6,7,8,9,10|state',
	];
	/*验证提示信息*/
	protected $message = [
		'repair_sn.require'		=> '维修编号不能为空',
		'repair_sn.repair_sn'	=> '维修编号已存在',
		'state.require'			=> '状态不能为空',
		'state.in'				=> '状态格式错误',
		'state.state'			=> '状态格式错误',
	];
	/*验证场景*/
	protected $scene = [
		'add'	=> ['repair_sn'],
	];

	/**
	 * 自定义方法
	 */
	protected function repair_sn($value, $rule, $data)
	{
		$where = [];
		if(isset($data['ids'])){
			$where['repair_id'] = ['neq',$data['ids']];
		}
		$count = Db::name('repair')
		->where('repair_sn',$value)
		->where($where)
		->count();
		return $count > 0 ? false : true;
	}
}